<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;

class DynamicController extends BaseController
{
    public $validate = [
        "del" => ["rules" => [
            "id" => "required|string|max:24",
        ]],
        "getDetail" => ["rules" => [
            "id" => "required|string|max:24",
        ]],
    ];

    /**
     * @path /dynamic/get-detail
     * @category 动态
     * @title 【有备注】详情
     * @method POST
     * @params [{"name":"id","type":"text","required":1,"example":"","desc":"动态ID"}]
     * @resBody {"success":true,"statusCode":200,"result":{"id":"动态ID","user_id":"用户ID","target_id":"动态主体ID","target_type":1,"type":1,"is_deleted":0,"created_at":"创建时间戳","user":{"id":"用户ID","nickname":"千千","avatar":"用户头像，如1.jpg"},"article":{"【注意】":"此节点在【文章动态】中才有值，否则为空对象","id":"文章ID","cover_url":"文章封面图，如1.jpg","title":"文章标题","description":"文章描述","is_deleted":0,"is_shield":0,"created_at":1598692662,"content":"这是文章内容"},"note":{"【注意】":"此节点在【笔记动态】中才有值，否则为空对象","id":"笔记ID","user_id":"用户ID","article_id":"文章ID","is_choice":0,"is_deleted":0,"is_public":1,"is_shield":0,"created_at":1600742930,"content":"笔记内容","selected":"文章节选","article":{"id":"文章ID","cover_url":"文章封面图，如1.jpg","title":"文章标题","description":"文章描述","is_deleted":0,"is_shield":0,"created_at":"创建时间戳"},"count":{"collect":0,"like":0,"comment":0}}},"message":"OK"}
     * @description 1.【前端】留意字段返回中【注意】的部分
     */
    public function getDetail(Request $request)
    {
        $params = $request->all();

        $data = service()->DynamicService->getDynamic($params['id']);

        return $this->apiReturn($data);
    }

    /**
     * @path /dynamic/del
     * @category 动态
     * @title 删除
     * @method POST
     * @params [{"name":"id","type":"text","required":1,"example":"","desc":"动态ID"}]
     * @resBody {"success":true,"statusCode":200,"result":true,"message":"OK"}
     */
    public function del(Request $request)
    {
        $params = $request->all();

        $data = service()->DynamicService->delDynamic($params['id'], $this->getCurrentUserId());

        return $this->apiReturn($data);
    }
}
